import { Component, Label, _decorator } from 'cc';
import { PlayerData } from '../../scenes/game-scene';

const { ccclass, property } = _decorator;

/** 游戏结束面板事件 */
export enum GameOverPanelEventType {
	/** 开始游戏 */
	StartGame = 'event_start_game',
	/** 显示主菜单 */
	ShowMenu = 'event_show_menu'
}

@ccclass('GameOverPanel')
export class GameOverPanel extends Component {
	@property(Label)
	playTimeLbl: Label = null;

	private data: PlayerData;

	start() {
		if (this.data) {
			console.log(this.data);
			this.playTimeLbl.string = this.data.playTime + '秒';
		}
	}

	public setData(data: PlayerData) {
		this.data = data;
	}

	private onClickHome() {
		this.node.emit(GameOverPanelEventType.ShowMenu);
	}

	private onClickPlay() {
		this.node.emit(GameOverPanelEventType.StartGame);
	}
}
